package meituan;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Stack;

public class three {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        Stack<Integer> stack = new Stack<>();
        stack.push(y);
        for (int i = 0; i < n; i++) {
            int a = scan.nextInt();
            int b = scan.nextInt();

            if(a==stack.peek()){
                stack.push(b);
            }
            else if(b==stack.peek()){
                stack.push(a);
            }
        }
        System.out.println(stack.size() + 1);

    }
}
